package com.pagoda.nerp.trade.common.enums;

/**
 * Created by Jungle on 2016/12/13.
 */
public enum ErrorCodeMappingEnums {

    // 系统级别错误码
    SUCCESS(0,"OK"),
    ERROR(-1,"系统繁忙，请稍后重试"),
    ERROR_INVALID_PARAMS(-2,"请求报文参数缺失或无效"),
    ERROR_HTTP_REQUEST_FAIL(-3,"HTTP接口调用失败"),
    ERROR_EXCEPTION_DATA(-4, "数据异常"),

    // DB 层面异常
    ERROR_EXCEPTION_DB_DML(-10,"DB操作异常"),
    ERROR_INVALID_DB_RECORD(-11,"数据库无此记录"),

    // 交易平台 - 运营端
    ERROR_EXCEPTION_USERS(30001,"账号不存在或密码错误"),
    ERROR_REPEAT_PHONENUMBER(30002,"手机号已被注册"),
    ERROR_EXCEPTION_CODE(30003, "验证码发送失败，无效手机号"),
    ERROR_INVALID_ACCOUNT(30004, "无效子账户"),
    ERROR_INVALID_VENDOR(30005, "无效供应商"),
    ERROR_INVALID_GOODS(30006, "无效商品"),
    ERROR_EXCEPTION_VENDOR_STATUS(30007, "供应商状态异常"),
    ERROR_INVALID_ROLE(30008, "无效角色"),
    
    //h5端
    ERROR_ACCOUNT_NOT_EXIST(40001,"账户不存在"),
    ERROR_ACCOUNT_SHIRO_AUTHENTICATE(40002,"用户登录认证失败");
    

    private int errorCode ;
    private String errorMsg;

    ErrorCodeMappingEnums(int errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
    }

    /**
     * 枚举类型的判断和获取
     * @param errorCode 错误码
     * @return 返回错误码对应的枚举信息
     */
    public static ErrorCodeMappingEnums statusOf(int errorCode){
        for(ErrorCodeMappingEnums error : values()){
            if(error.getErrorCode() == errorCode){
                return error;
            }
        }
        return null;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg == null ? "" : errorMsg.trim();
    }
}
